﻿<script src="~/admui-13945148017-1592211513218/public/themes/global/js/components/bootstrap-datepicker.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.zh-CN.min.js"></script>
<link href="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/css/examples/tables/datatable.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.min.js"></script>
<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-header">
            <h1 class="page-title">权限配置列表</h1>
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a class="icon wb-home" href="javascript:;">权限配置管理</a>
                </li>
                <li class="breadcrumb-item active">权限配置列表</li>
            </ol>
        </div>
        <div class="page-content">
            <div class="panel">
                <div class="panel-body container-fluid">
                    <h4 class="example-title">权限配置管理</h4>
                    <div class="row">
                        <div class="form-group col-sm-3">
                            <label class="control-label" for="inputBasicPassword">权限配置名称</label>
                            <input type="text" class="form-control" id="QuanXianPeiZhiMingCheng" name="" placeholder="权限配置名称" autocomplete="off" />
                        </div>
                        <div class="form-group col-sm-3" style="padding-top:27px">
                            <button type="button" id="tianjia" class="btn  btn-success" style="width: 100%; float: left;display:block;" onclick="TianJia()"><i class="icon wb-search"></i>添加</button>
                            <button type="button" id="xiugai" class="btn  btn-success" style="width: 100%; float: left;display:none;" onclick="XiuGai()"><i class="icon wb-search"></i>修改</button>
                            <button class="btn btn-primary" data-target="#exampleFormModal" data-toggle="modal" type="button" id="btn_Xz1" style="display: none;">编辑</button>
                        </div>
                        <div class="form-group col-sm-3" style="padding-top:27px">
                            <button type="button" id="quxiao" class="btn btn-outline btn-success" style="width: 100%;display:none;" onclick="QuXiao();">取消</button>
                        </div>
                    </div>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="dataTableExample" data-plugin="dataTable">
                        <thead>
                            <tr>
                                <th>权限配置名称</th>
                                <th>状态</th>
                                @*<th>权限名称</th>*@
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="pinshicunchu"></div>
<div id="pinshicunchushuju"></div>
<div class="modal fade example-modal-lg" id="exampleFormModal" aria-hidden="true" aria-labelledby="exampleFormModalLabel" role="dialog" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog modal-lg" style="width: 100%; height: 80%">
        <div class="modal-content" style="width: 100%; height: 80%">
            <div class="modal-header" style="background-color:#0099FF">
                <label id="CunId" style="display:none"></label>
                <button type="button" class="close" data-dismiss="modal" id="guanbiaddkehu" onclick="" aria-label="关闭">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" style="color:white;" id="exampleFormModalLabel">权限配置</h4>
            </div>
            <div class="row" style="text-align:center; margin-left: 70px;" id="DuoXuan">

            </div>
            <div class="row">
                <div class="form-group col-sm-3"></div>
                <div class="form-group col-sm-6">
                    <button type="button" id="bt_ChongZhiE" class="btn btn-outline btn-success" style="width: 100%;" onclick="SubmitUpdate();">保存</button>
                </div>
                <div class="form-group col-sm-3"></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#SpanXiTong").click();
        $("#pinshicunchu").val(0);
        $("#pinshicunchushuju").val(0);
        bang();
    });
    function TianJia() {
        var QuanXianPeiZhiMingCheng = $("#QuanXianPeiZhiMingCheng").val();
        if (QuanXianPeiZhiMingCheng == "") {
            alert("权限配置名称不能为空");
        } else {
            $.ajax({
                url: '../QuanXian/QuanXianPeiZhiAdd',
                data: { QuanXianPeiZhiMingCheng: QuanXianPeiZhiMingCheng },
                type: "post",
                dataType: "text",
                success: function (response) {
                    alert("提交成功");
                    bang();
                }
            });
        }
    }
    function ZhuangTaiXG(id) {
        $.ajax({
            url: '../QuanXian/PeiZhiZhuangTaiXG',
            data: { Id: id },
            type: "post",
            dataType: "text",
            success: function (response) {
                alert("修改成功");
                bang();
            }
        });
    }
    function HuiBang(id) {
        $("#pinshicunchu").val(id);
        $.ajax({
            url: '../QuanXian/PeiZhiMingChengHuiBang',
            data: { Id: id },
            type: "post",
            dataType: "text",
            success: function (response) {
                $("#QuanXianPeiZhiMingCheng").val(response);
                var currentBtn1 = document.getElementById('tianjia');
                var currentBtn2 = document.getElementById('xiugai');
                var currentBtn3 = document.getElementById('quxiao');
                currentBtn1.style.display = "none";
                currentBtn2.style.display = "block";
                currentBtn3.style.display = "block";
            }
        });
    }
    function XiuGai() {
        var id = $("#pinshicunchu").val();
        var QuanXianPeiZhiMingCheng = $("#QuanXianPeiZhiMingCheng").val();
        if (QuanXianPeiZhiMingCheng == "") {
            alert("权限名称不能为空");
        } else {
            $.ajax({
                url: '../QuanXian/PeiZhiMingChengXiuGai',
                data: { Id: id, QuanXianPeiZhiMingCheng: QuanXianPeiZhiMingCheng },
                type: "post",
                dataType: "text",
                success: function (response) {
                    alert("修改成功");
                    bang();
                    $("#pinshicunchu").val(0);
                    $("#QuanXianPeiZhiMingCheng").val("");
                    var currentBtn1 = document.getElementById('tianjia');
                    var currentBtn2 = document.getElementById('xiugai');
                    var currentBtn3 = document.getElementById('quxiao');
                    currentBtn1.style.display = "block";
                    currentBtn2.style.display = "none";
                    currentBtn3.style.display = "none";
                }
            });
        }
    }
    function QuXiao() {
        $("#QuanXianPeiZhiMingCheng").val("");
        var currentBtn1 = document.getElementById('tianjia');
        var currentBtn2 = document.getElementById('xiugai');
        var currentBtn3 = document.getElementById('quxiao');
        currentBtn1.style.display = "block";
        currentBtn2.style.display = "none";
        currentBtn3.style.display = "none";
    }
    function TanCeng(id) {
        $("#pinshicunchushuju").val(id);
        $("#btn_Xz1").click();
        $.ajax({
            url: '../QuanXian/HuiBangDuoXuan1',
            data: { Id: id },
            type: "post",
            dataType: "text",
            success: function (response) {
                $("#DuoXuan").html(response);
            }
        });
    }
    function SubmitUpdate() {
        var id = $("#pinshicunchushuju").val();
        var quanxian = [];
        var obj = document.getElementsByName('checkAll'); //选择所有name="'test'"的对象，返回数组
        //取到对象数组后，我们来循环检测它是不是被选中
        var s = '';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                quanxian.push(obj[i].value);
            }
        }
        for (var i = 0; i < quanxian.length; i++) {
            if (i == 0) {
                s += quanxian[i];
            } else {
                s += ',' + quanxian[i];
            }
        }
        $.ajax({
            url: '../QuanXian/PeiZhiQuanXian',
            data: { Id: id, QuanXianId: s },
            type: "post",
            dataType: "text",
            success: function (response) {
                $("#pinshicunchushuju").val(0);
                alert("配置成功");
                $("#guanbiaddkehu").click();
            }
        });
    }
    //function pinjie(id) {
    //    var a;
    //    $.ajax({
    //        url: '../QuanXian/pinjie',
    //        data: { Id: id },
    //        type: "post",
    //        dataType: "text",
    //        success: function (response) {
    //            alert(response);
    //            a = response;
    //        }
    //    });
    //    alert(a);
    //    return a;
    //}
    function bang() {
        var lang = {
            "sProcessing": "大量处理中，请稍后...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        $("#dataTableExample").dataTable().fnDestroy();
        $('#dataTableExample').dataTable({
            "order": [[0, "asc"]],
            "language": lang,
            "processing": true,
            "serverSide": true,
            //"bStateSave": true,//状态保持模式
            "searching": false,//禁用搜索
            ajax: function (data, callback, settings) {
                //封装请求参数
                var param = {};
                param.sw = "";
                param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length) + 1;//当前页码
                param.dir = data.order[0].dir;
                param.column = data.order[0].column;

                //ajax请求数据
                $.ajax({
                    type: "POST",
                    url: "../QuanXian/QuanXianPeiZhiFenYe",
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        //setTimeout仅为测试延迟效果
                        setTimeout(function () {
                            //封装返回数据
                            var returnData = {};
                            returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.data;//返回的数据列表
                            //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                            callback(returnData);
                        }, 200);
                    }
                });
            },
            "columns": [
                { "data": "PeiZhiMingCheng" },
                { "data": "BeiZhu1" },
                //{ "data": "QuanXianMingCheng", render: function (data, type, row) { return "<label>" + pinjie(row.Id) + "</label>" } },
                { "data": null }
            ],
            columnDefs: [{
                //   指定第最后一列
                targets: -1,
                //加下面属性 不参与排序
                sortable: false,
                render: function (data, type, row, meta) {
                    if (row.BeiZhu1 == "启用") {
                        return '<button type="button" class="btn btn-outline btn-default" onclick="HuiBang(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>' +
                            '<button type="button" class="btn btn-outline btn-default" onclick="ZhuangTaiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>停用</button>' +
                            '<button type="button" class="btn btn-outline btn-default"  onclick="TanCeng(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>权限配置</button>';
                    } else if (row.BeiZhu1 == "停用") {
                        return '<button type="button" class="btn btn-outline btn-default" onclick="HuiBang(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>' +
                            '<button type = "button" class="btn btn-outline btn-default" onclick = "ZhuangTaiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>启用</button>' +
                            '<button type="button" class="btn btn-outline btn-default" onclick="TanCeng(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>权限配置</button>';
                    } else {
                        return '<button type="button" class="btn btn-outline btn-default" onclick="HuiBang(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>' +
                        '<button type="button" class="btn btn-outline btn-default" onclick="TanCeng(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>权限配置</button>'
                    }
                }
            }]
        });
    }
</script>